package net.zjitc.dao.User.impl;

import net.zjitc.damain.User.User;
import net.zjitc.dao.User.UserDao;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Administrator on 2017/3/10.
 */
@Repository
public class UserDaoImpl implements UserDao{
    @Resource
    private SessionFactory sessionFactory;
    protected Session getSession(){
        Session session = sessionFactory.getCurrentSession();
        return session;
    }


    @Override
    public List<User> findAll() {
        return getSession().createQuery(
                "from User ")
                .list();
    }

    @Override
    public User getById(Integer id) {
        return (User) getSession().createQuery(
                "from User where id=?")
                .setParameter(0,id)
                .uniqueResult();
    }
    @Override
    public void Delete(User user) {
        getSession().delete(user);
    }

    @Override
    public void save(User model) {
        getSession().save(model);
    }

    @Override
    public User findByUsernamePassword(String username, String password) {
        return null;
    }
}
